package com.xgame.server.dbtool;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.xgame.server.db.mapper.BossrankMapper;
import com.xgame.server.db.model.Bossrank;
import com.xgame.server.netty.proto.Game;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class BossrankCsTool {
    @Resource
    private BossrankMapper bossrankMapper;

    //插入击杀排行榜
    public Integer insertBossRank(Game.BossRankCS data) throws Exception {
        Bossrank map = new Bossrank();
        map.setAccount(data.getAccount());
        map.setPlayerId(data.getPlayerID());
        map.setRankValue(data.getRankValue());
        map.setRewardId(data.getRewardId());
        map.setLastRecord(data.getLastRecord());

        return bossrankMapper.insert(map);
    }

    //更新玩家记录
    public Integer updateBossRank(Game.BossRankCS data) throws Exception {
        EntityWrapper<Bossrank> userWrapper = new EntityWrapper<>();
        userWrapper.eq("account", data.getAccount());

        Bossrank map = new Bossrank();
        map.setAccount(data.getAccount());
        map.setPlayerId(data.getPlayerID());
        map.setRankValue(data.getRankValue());
        map.setRewardId(data.getRewardId());
        map.setLastRecord(data.getLastRecord());

        return bossrankMapper.update(map, userWrapper);
    }

    //删除记录
    public Integer deleteBossRank(Game.BossRankCS data) throws Exception {
        EntityWrapper<Bossrank> userWrapper = new EntityWrapper<>();
        userWrapper.eq("account", data.getAccount());

        return bossrankMapper.delete(userWrapper);
    }

    //查询记录
    public List<Bossrank> selectBossRank(String account) throws Exception {
        EntityWrapper<Bossrank> userWrapper = new EntityWrapper<>();
        userWrapper.eq("account", account);

        return bossrankMapper.selectList(userWrapper);
    }
}
